IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PurchaseOrder]') AND type in (N'U'))
BEGIN
	CREATE TABLE [dbo].[PurchaseOrder](
	[PurchaseOrderId] [bigint] IDENTITY(1,1) NOT NULL,
	[PurchaseOrderDate] [datetime] NOT NULL,
	[ItemName] [varchar](250) NOT NULL,
	[Itemquantity] [bigint] NOT NULL,
	[VendorId] [bigint] NULL,
	[WorkflowInstanceId] [int] NOT NULL,
	[Price] [decimal](18, 2) NOT NULL,
	[IsCredit] [bit] NOT NULL,
        CONSTRAINT [PK_PurchaseOrder] PRIMARY KEY CLUSTERED 
        ([PurchaseOrderId] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
        ) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WorkflowInstances]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[WorkflowInstances](
	[WorkflowInstanceId] [int] IDENTITY(1,1) NOT NULL,
	[WorkflowName] [nvarchar](500) NOT NULL,
	[Comments] [nvarchar](500) NULL,
	[StateName] [nvarchar](500) NOT NULL,
	[ActivityName] [nvarchar](500) NOT NULL,
	[LastModifiedBy] [nvarchar](500) NOT NULL,
	[LastModifiedOn] [datetime] NOT NULL,
	[Attributes] [varchar](5000) NULL,
	[WorkflowType] [varchar](500) NULL,
        CONSTRAINT [PK_WorkflowInstances] PRIMARY KEY CLUSTERED 
        ([WorkflowInstanceId] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
        ) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WorkflowInstanceAuditTrails]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[WorkflowInstanceAuditTrails](
	[WorkflowInstanceAuditTrailID] [int] IDENTITY(1,1) NOT NULL,
	[WorkflowInstanceId] [int] NOT NULL,
	[WorkflowName] [nvarchar](500) NOT NULL,
	[Comments] [nvarchar](500) NULL,
	[StateName] [nvarchar](500) NOT NULL,
	[ActivityName] [nvarchar](500) NOT NULL,
	[LastModifiedBy] [nvarchar](500) NOT NULL,
	[LastModifiedOn] [datetime] NOT NULL,
	[Attributes] [varchar](5000) NULL,
	[WorkflowType] [varchar](500) NULL,
        CONSTRAINT [PK_WorkflowInstanceAuditTrails] PRIMARY KEY CLUSTERED 
        ([WorkflowInstanceAuditTrailID] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
        ) ON [PRIMARY]
END
GO
